<?php
include_once('common/header.php');	
if($AppUI->id <= 0 || !isset($_SERVER['HTTP_REFERER'])) {	
	$arrJson = array('error'=>1,'msg'=>$arrError[1]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	exit();
}
$intError				= 0;
$strMessage				= '';
$strData				= '';
$strRefer				= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$intRequestId			= $objRequest->getParam('requestid',0);
$intRequesterId			= $objRequest->getParam('uid',0);
$intType				= $objRequest->getParam('type',0);
$intRefObjId			= $objRequest->getParam('refobjid',0);
$strToken				= $objRequest->getParam('token','');
$strSession				= isset($_SESSION['reDenied' . $intRequestId]) ? $_SESSION['reDenied' . $intRequestId] : '';
$objURequest			= new URequest();
if($intRequestId && $intRequesterId && $intType && $intRefObjId && $strToken != '' && $strSession != '' && $strSession == $strToken && Vfriend_Function::isValidLink($strRefer)) {
	unset($_SESSION['reDenied' . $intRequestId]);
	
	$objVfriendUser		= new Vfriend_User();
	$objUser			= $objVfriendUser->getInfo($intRequesterId);
	$objReInfo			= $objURequest->get($AppUI->id,$intRequestId);
	if($objReInfo) {
		switch(abs($intType)) {
			case 1:
				$objURequest->denyGift($AppUI->id, $intRequesterId, $intRefObjId, $intError);
				if($intError == 0) {
					$objURequest->deleteRequest($intRequestId,$AppUI->id,$intRequesterId,$intType);	
					$strMessage	= $arrMessage[13];					
				} else {
					$strMessage	= $arrError[1];
				}
				break;
			case 2:
				$intError = $objURequest->denyGiveVon($AppUI->id, $intRequesterId, $intRefObjId,$intPlusVon);
				if($intError == 0) {
					$objURequest->deleteRequest($intRequestId,$AppUI->id,$intRequesterId,$intType);	
					$strMessage	= $arrMessage[14];
					$strMessage	= str_replace('[intVon]', Vfriend_Function::numberFormat($intPlusVon), $strMessage);
				} else {
					$strMessage	= $arrError[1];
				}
				break;
			case 3:
			case 4:
			case 5:
			case 6:		
				$objURequest->deleteRequest($intRequestId,$AppUI->id,$intRequesterId,$intType);	
				$strMessage	= $arrMessage[$intType+12];
				break;
			case 7:
				$intPlusLike 	= 0;
				$intError 		= $objURequest->denyGiveLike($AppUI->id, $intRequesterId, $intRefObjId, $intPlusLike);
				if($intError == 0) {
					$objURequest->deleteRequest($intRequestId,$AppUI->id,$intRequesterId,$intType);	
					$strMessage	= $arrMessage[21];
					$strMessage	= str_replace('[intLike]', Vfriend_Function::numberFormat($intPlusLike), $strMessage);
				} else {
					$strMessage	= $arrError[1];
				}
				break;
			case 9:
				$arrRequest = $objURequest->get($AppUI->id,$intRequestId);
				if($arrRequest) {
					$arrRequest['message']	= Zend_Json::decode($arrRequest['message']);
					$intOfflineId			= $arrRequest['message']['offlineid'];
					$objOffline 			= new Offline();
					$arrOjoin				= $objOffline->getOjoin($AppUI->id,$intOfflineId);
					$intError				= $objOffline->ojoinUpdateStatus($AppUI->id, $arrOjoin['ojoinid'], $intOfflineId, $intRequesterId, -2);
					if($intError == 0) {
						$strMessage	= $arrMessage[32];
					} else {
						$strMessage	= $arrError[$intError+40];
					}
				} else {
					$intError 	= 1; 
					$strMessage	= $arrError[1];
				}
				break;
		}
	
		$strMessage	= str_replace('[strFullname]', $objUser->fullnamevn, $strMessage);
		
	} else {
		$intError		= 1;
		$strMessage		= $arrError[$intError];
	}
}
$arrRequest				= $objURequest->getAll($AppUI->id);
$arrData				= array();
if($arrRequest) {
	foreach($arrRequest as $value) {
		$value['message']	= Zend_Json::decode($value['message']);
		$arrData[]			= $value;
	}
}
$this->view->arrRequest = $arrData;
$this->view->ajax		= 1;
$objView 				= Zend_Registry::get('objView');
$strData				= $objView->fetch('ajax/request.tpl');
$arrJson 				= array('error'=>$intError,'msg'=>$strMessage,'data'=>$strData);
echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
exit();
?>